package plugins.systemInfoModule
{
	import core.MainManager;
	
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	import flash.events.TimerEvent;
	import flash.system.System;
	import flash.utils.Timer;
	/**
	 * 显示系统信息，包括帧速，使用的内存，鼠标的坐标
	 * 通过按键"1"可以控制这个界面的显示和隐藏
	 */ 
	public class SystemInfoModule extends Sprite
	{
		private var frameRater:FPS;
		private var timer:Timer;
		private var systemInfoSwc:SystemInfoSwc;
		public function SystemInfoModule()
		{
			super();
			init();
		}
		private function init():void
		{
			initFPS();
			initSystemInfo();
			infoRefresher();
			initKeyControl();
		}
		private function initFPS():void
		{
			frameRater=new FPS();
			this.addChild(frameRater);
		}
		private function initSystemInfo():void
		{
			systemInfoSwc=new SystemInfoSwc();
			this.addChild(systemInfoSwc);
			systemInfoSwc.fps_text.mouseEnabled=false;
			systemInfoSwc.memory_text.mouseEnabled=false;
			systemInfoSwc.x_text.mouseEnabled=false;
			systemInfoSwc.y_text.mouseEnabled=false;
		}
		//时刻刷新信息
		private function infoRefresher():void
		{
			timer=new Timer(500,0);
			timer.addEventListener(TimerEvent.TIMER,on_timer);
			timer.start();
		}
		//timer刷新的时候
		private function on_timer(e:TimerEvent):void
		{
			if(systemInfoSwc.fps_text!=null) systemInfoSwc.fps_text.text=frameRater.fps+" FPS";
			if(systemInfoSwc.memory_text!=null) systemInfoSwc.memory_text.text=int(System.totalMemory/(1024*1024))+" MB";
			if(systemInfoSwc.x_text!=null) systemInfoSwc.x_text.text=this.stage.mouseX.toString();
			if(systemInfoSwc.y_text!=null) systemInfoSwc.y_text.text=this.stage.mouseY.toString();
		}
		private function initKeyControl():void
		{
			MainManager.getInstance().stage.addEventListener(KeyboardEvent.KEY_DOWN,function(e:KeyboardEvent):void
			{
				if(e.keyCode==49)
				{
					if(visible)
					{
						 visible=false;
					}else
					{
						visible=true;
					}
				}
			});
		}
		public function dispose():void
		{
			
		}
	}
}